export const setStore = (key: string, data: any, timeout = 0) => {
  const storeData = {
    data,
    timeout,
    time: new Date().getTime(),
  }
  localStorage.setItem(key, JSON.stringify(storeData))
}

export const getStore = (key: string) => {
  const storeData = localStorage.getItem(key)
  if (storeData) {
    const data = JSON.parse(storeData)
    if (data.timeout === 0 || new Date().getTime() - data.time < data.timeout) {
      return data.data
    }
    localStorage.removeItem(key)
  }
  return null
}
